
#include "Client.h"
#include <thread>

void cmd_fun(Client client) {
	while (true) {

		char cmdBuf[1024] = {};

		printf("input cmd: \n");
		scanf("%s", cmdBuf);

		int n = 0;
		if (0 == strcmp("logout", cmdBuf)) {

			LogOut logOut = {};
			client.send_msg((char *)&logOut, sizeof(LogOut));
			printf("logout\n");
			client.stop_self();
			break;

		}
		else if (0 == strcmp("login", cmdBuf)) {

			char nameBuf[128] = {};
			char passwdBuf[128] = {};
			printf("input name: \n");
			scanf("%s", nameBuf);
			printf("input passwd: \n");
			scanf("%s", passwdBuf);

			printf("pass: %s\n", passwdBuf);

			Login login = {};
			strcpy(login.name, nameBuf);
			strcpy(login.passwd, passwdBuf);

			client.send_msg((char*)&login, sizeof(Login));

		}
		else if (0 == strcmp("person_info", cmdBuf)) {
			PersonInfo person = {};
			client.send_msg((char*)&person, sizeof(PersonInfo));
		}
	}
}

int main() {

	Client client;
	char ip[] = "127.0.0.1";
	client.connect_server(ip, 6666);
	std::thread cmd(cmd_fun, client);
	cmd.detach();// exit important!!!

	client.run();

	return 0;
}